/**
 * 输入验证
 * @param name
 * @param value
 * @param roles
 * @param message
 */
export default function validateInput(name: string, value: string, roles: string[], message?: string) {
  for (const role of roles) {
    if (role === 'required' && !value) {
      return `请输入${name}`;
    }
    if (role === 'email' && !/\S+@\S+\.\S+/.test(value)) {
      return message || `请输入正确格式的${name}`;
    }
    if (role === 'phone' && !/^1[3-9]\d{9}$/.test(value)) {
      return message || `请输入正确格式的${name}`;
    }
  }
  return '';
}
